﻿//using RestSharp;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace FreeDream.Common
//{
//    public class RestSharpHelper
//    {
//        #region 10.0  ReSharpPost 方法
//        /// <summary>
//        /// ReSharpPost json data
//        /// </summary>
//        /// <param name="url"></param>
//        /// <param name="data"></param>
//        /// <returns></returns>
//        public static string ReSharpPost(string url, string data)
//        {
//            try
//            {
//                //QueenLogger.Debug(string.Format("ReSharpPost URL:{0}--DATA{1}", url, data), "ReSharpPost");
//                var client = new RestClient(url);
//                var request = new RestRequest(Method.POST);
//                request.AddHeader("cache-control", "no-cache");
//                request.AddHeader("content-type", "application/json;charset=utf-8");
//                if (!string.IsNullOrEmpty(data))
//                {
//                    request.AddParameter("application/json;charset=utf-8", data, ParameterType.RequestBody);
//                }
//                IRestResponse response = client.Execute(request);
//                string content = response.Content;
//                //QueenLogger.Debug(string.Format("Return:{0}--DATA{1}", url, content), "ReSharpPost");
//                return content;
//            }
//            catch (Exception ex)
//            {
//                QueenLogger.Error(string.Format("【ReSharpPost 请求异常】请求返回：{0}|地址:{1}|MSG:{2}|StackTrace:{3}", ex.Message, url, ex.Message, ex.StackTrace));
//                return "500";
//            }
//        }

//        public static string ReSeSharpGet(string url)
//        {
//            try
//            {
//                var client = new RestClient(url);
//                var request = new RestRequest(Method.GET);
//                request.AddHeader("Cache-Control", "no-cache");
//                request.AddHeader("content-type", "application/json;charset=utf-8");
//                IRestResponse response = client.Execute(request);
//                QueenLogger.Debug(string.Format("ReSeSharpGet：{0}--Response{1}", url, response.Content));
//                return response.Content;
//            }
//            catch (Exception ex)
//            {
//                QueenLogger.Error(string.Format("【ReSeSharpGet 请求异常】请求返回：{0}|地址:{1}|MSG:{2}|StackTrace:{3}", ex.Message, url, ex.Message, ex.StackTrace));
//                return "";
//            }
//        }
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="url"></param>
//        /// <param name="client_credentials"></param>
//        /// <param name="client_id"></param>
//        /// <param name="client_secret"></param>
//        /// <returns></returns>
//        public static string GetHzAccessToken(string url, string client_credentials, string client_id, string client_secret)
//        {
//            var client = new RestClient(url);
//            var request = new RestRequest(Method.POST);
//            request.AddHeader("cache-control", "no-cache");
//            request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
//            request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
//                string.Format("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"grant_type\"\r\n\r\n{0}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_id\"\r\n\r\n{1}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_secret \"\r\n\r\n{2}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", client_credentials, client_id, client_secret), ParameterType.RequestBody);
//            IRestResponse response = client.Execute(request);
//            return response.Content;
//        }

//        public static string ApplyTemporaryId(string url, string data, string token)
//        {
//            var client = new RestClient(url);
//            var request = new RestRequest(Method.POST);
//            request.AddHeader("cache-control", "no-cache");
//            request.AddHeader("Content-Type", "application/json");
//            request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
//            request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
//                string.Format("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;" +
//                " name=\"key\"\r\n\r\n{0}\r\n" +
//                "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; " +
//                "name=\"json\"\r\n\r\n{1}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", token, data), ParameterType.RequestBody);
//            IRestResponse response = client.Execute(request);
//            QueenLogger.Debug(string.Format("ReSharpPost URL:{0}--DATA{1},Response{2}", url, data, response.Content), "ReSharpPost");
//            return response.Content;
//        }

//        #endregion

//        #region 10.1  ReSharpPost 提交文件方法（无锡户政使用）
//        public static async Task<string> PostFiles(string url, List<string> filePaths)
//        {
//            var client = new RestClient(url)
//            {
//                Timeout = -1
//            };
//            var request = new RestRequest(Method.POST);
//            foreach (var path in filePaths)
//            {
//                //request.AddFile("file", "/C:/Users/Administrator/Pictures/示例图片/timg (1).jpg");
//                request.AddFile("file", path);
//            }
//            IRestResponse response = await client.ExecuteAsync(request);
//            return response.Content;
//        }
//        #endregion
//    }
//}
